package com.polaris.live.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.StringUtils
import com.hjq.shape.view.ShapeTextView
import com.polaris.live.R
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.resp.bean.MyBeansBannerBean
import com.polaris.live.translation.R.string
import com.polaris.live.utils.CommonUtils
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder

/**
 * MyBeansBannerAdapter
 *
 * @author Created by 半仙 on 2024/4/12/012 11:28
 */
class MyBeansBannerAdapter : BaseBannerAdapter<MyBeansBannerBean>() {

    override fun bindData(
        holder: BaseViewHolder<MyBeansBannerBean>,
        data: MyBeansBannerBean?,
        position: Int,
        pageSize: Int,
    ) {
        val tvBeans = holder.findViewById<ShapeTextView>(R.id.tv_beans)
        val tvWithdraw = holder.findViewById<TextView>(R.id.tv_withdraw)
        val ivMyBeansWhat = holder.findViewById<ImageView>(R.id.iv_my_beans_what)
        val vLine = holder.findViewById<View>(R.id.v_line)
        val tvGetMoreBeans = holder.findViewById<ShapeTextView>(R.id.tv_get_more_beans)
        val tvMyBeansBalance = holder.findViewById<TextView>(R.id.tv_my_beans_balance)
        val gainCoin = data?.gainCoin
        val sendGainCoin = data?.coin
        if (gainCoin != null && sendGainCoin != null) {
            tvBeans.text = "${gainCoin + sendGainCoin} "
        }
        if (UserManager.getUser().extension?.allowWithdraw == true) {
            //提现入口
            if (data?.allowWithdraw == true) {
                tvWithdraw.visibility = View.VISIBLE
                ivMyBeansWhat.visibility = View.VISIBLE
            } else {
                tvWithdraw.visibility = View.GONE
                ivMyBeansWhat.visibility = View.GONE
            }
        } else {
            ivMyBeansWhat.visibility = View.GONE
            tvWithdraw.visibility = View.GONE
        }

        //公会女成员才有入口
        if (!CommonUtils.isMan(UserManager.getUser().sex) && UserManager.getUser().profile?.agencyId != null) {
            tvGetMoreBeans.visibility = View.VISIBLE
        } else {
            vLine.visibility = View.GONE
            tvGetMoreBeans.visibility = View.GONE
        }

        if (position == 0) {
            tvMyBeansBalance.setTextColor(ColorUtils.getColor(R.color.color_924a1c))
            ivMyBeansWhat.setImageResource(R.drawable.btn_doubt_black)
            tvMyBeansBalance.text = StringUtils.getString(string.my_beans_balance)
        } else {
            tvMyBeansBalance.setTextColor(ColorUtils.getColor(R.color.color_9757ff))
            ivMyBeansWhat.setImageResource(R.drawable.btn_doubt_black_purple)
            tvMyBeansBalance.text = StringUtils.getString(string.agency_beans_balance)
        }

        ivMyBeansWhat.setOnSingleClickListener {
            onMyBeansWhatClick?.invoke(position)
        }
        tvWithdraw.setOnSingleClickListener {
            onWithdrawClick?.invoke(position)
        }
        tvGetMoreBeans.setOnSingleClickListener {
            onGetMoreBeansClick?.invoke(position)
        }
    }

    private var onWithdrawClick: ((position: Int) -> Unit)? = null
    fun setOnWithdrawClick(l: (position: Int) -> Unit) {
        onWithdrawClick = l
    }

    private var onMyBeansWhatClick: ((position: Int) -> Unit)? = null
    fun setOnMyBeansWhatClick(l: (position: Int) -> Unit) {
        onMyBeansWhatClick = l
    }

    private var onGetMoreBeansClick: ((position: Int) -> Unit)? = null
    fun setOnGetMoreBeansClick(l: (position: Int) -> Unit) {
        onGetMoreBeansClick = l
    }

    override fun getLayoutId(viewType: Int): Int {
        return R.layout.adapter_my_beans_banner
    }

}